package servlet;

import service.GoodsService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
import java.util.Map;

@WebServlet("/index")
public class IndexServlet extends HttpServlet {

    private GoodsService gService=new GoodsService();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {


        System.out.println("IndexServlet is called.");
        PrintWriter out = response.getWriter();
        out.println("Hello from IndexServlet!");
        //取得首页轮播图展示
        Map<String,Object> scrollGoods = gService.getScrollGoods();
        request.setAttribute("scroll", scrollGoods);
        //取得热销商品
        List<Map<String,Object>> hotList = gService.getHotGoodsList();
        System.out.println("servlet:"+hotList);

        request.setAttribute("hotList", hotList);
//        //取得新品商品
        List<Map<String,Object>> newList = gService.getNewGoodsList();
        request.setAttribute("newList", newList);

        request.getRequestDispatcher("/index.jsp").forward(request, response);
    }
}
